package com.ecity.view {
	import com.ecity.events.PageEvent;
	import com.ecity.panels.MenuPlane;
	import com.ecity.panels.SinglePanel;
	import com.ecity.panels.SpinPanel;
	import com.ecity.util.UIFactory;
	import com.greensock.TweenLite;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import org.papervision3d.core.math.Sphere3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import flash.display.Sprite; 
	import flash.filters.BitmapFilterQuality; 
	import flash.filters.GlowFilter;
	
	/**
	 * ...
	 * @author Yicheng.Zhang
	 */
	public class PageView extends Sprite {
		private var _spinWorld:Viewer3d;
		private var _spinPage:Sprite;
		private var _spiner:SpinPanel;
		/////////////////////////////////
		private var _menuWorld:Viewer3d;
		private var _menuPage:Sprite;
		private var _menus:MenuPlane;
		////////////////////////////////
		private var _earth:Sphere;
		/**
		 * constructor
		 */
		public function PageView(){
			_earth = new Sphere(null, 50, 10, 8);
		}
		
		
		/**
		 * initialize the page 
		 */
		public function initPage():void {
			var mc:MovieClip = UIFactory.getMovieClip("bg") as MovieClip;
			this.addChild(mc);
			var screenbg:MovieClip = UIFactory.getMovieClip("screenbg") as MovieClip;
			screenbg.x = 200;
			screenbg.y = 100;
			
			_earth.material = new BitmapMaterial(UIFactory.getBitmapData("earth_c"));
			initSpinPanel();
			this.addChild(screenbg);
		}
		
		private function initSpinPanel():void {
			_spinWorld = new Viewer3d();
			_spinWorld.camera.zoom = 135;
			_spinWorld.y = -200;
			_spinPage = new Sprite();
			var material:BitmapMaterial = new BitmapMaterial(UIFactory.getBitmapData("spinFrame",true),true);
			_spiner = new SpinPanel(8, material);
			this.addChild(_spinWorld);
			_spinWorld.setCameraTarget(_spiner.targetPoint);
			
			_spinWorld.addModel(_spiner);
			
			_spiner.y = -100;

			initMenuPanel();
		}
		
		private function initMenuPanel():void {
			_menus = new MenuPlane();
			_menus.addEventListener(PageEvent.MENU_CLICKED, onMenuCicked);
			var single1:SinglePanel = new SinglePanel();
			_menus.addSinglePlane(single1, "sss", 0);
			_menuWorld = new Viewer3d();
			_menuWorld.y = 200;
			_menuWorld.addModel(_earth);
			_earth.x = -200;
			_earth.y = 200;
			_menuWorld.camera.zoom = 100;
			_menuWorld.addModel(_menus);
			this.addChild(_menuWorld);
			addEventListener(Event.ENTER_FRAME, renderEnterFrame);
		}
		
		private function onMenuCicked(e:PageEvent):void {
			_spiner.menuControlSpin();
		}
		
		
		private function renderEnterFrame(e:Event):void {
			_earth.rotationY += 2;
			_spinWorld.renderFrame();
			_menuWorld.renderFrame();
		}
		
	}

}